package com.bootx;

import java.io.File;
import java.net.URL;

import java.net.HttpURLConnection;

public class NetImageHeaderType {
    public static String getContentType(String imageUrl){
        System.out.println(imageUrl);
       try {
           URL url = new URL(imageUrl);
           HttpURLConnection conn = (HttpURLConnection) url.openConnection();
           conn.setRequestMethod("HEAD");
           conn.connect();
           String contentType = conn.getContentType();
           conn.disconnect();
           return contentType;
       }catch (Exception e){
           e.printStackTrace();
       }
       return "image/png";
    }

    public static void main(String[] args) {
        String urlStr = "https://s8.51cto.com/oss/202403/25/020a98671f96283e0b7567ec36141a1226bbf9.webp";
        String contentType = getContentType(urlStr);
        File file = new File(urlStr);
    }
}
